package com.zzh.ThreadPoolExecutor;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 *@ClassName ThreadPoolExectorDemo
 *@date 2021/3/18 20:45
 *@Version 1.0
 *@Description //
 */
@Slf4j
public class ThreadPoolExectorDemo {
    public static void main(String[] args) {
//        for (int i =0 ; i< 300;i++) {
//            new Thread(new Runnable() {
//                @Override
//                public void run() {
////                    System.out.println();
//                }
//            });
//        }

        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                5,
                20,
                3000,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(5));

        for (int i=0;i<6;i++){
            threadPoolExecutor.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println("i m task ："+Thread.currentThread().getName());
                }
            },i);
        }

        threadPoolExecutor.shutdown();  //running->shutdown
        threadPoolExecutor.shutdownNow(); //running->stop
    }
}
